package cn.kgc.vue.service.impl;

import cn.kgc.vue.commons.QueryCondition;
import cn.kgc.vue.commons.ResponseResult;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.vue.entity.Schedule;
import cn.kgc.vue.service.ScheduleService;
import cn.kgc.vue.mapper.ScheduleMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
* @author 11839
* @description 针对表【sys_schedule】的数据库操作Service实现
* @createDate 2024-06-28 15:23:44
*/
@Service
public class ScheduleServiceImpl extends ServiceImpl<ScheduleMapper, Schedule>
    implements ScheduleService{

    @Resource
    private ScheduleMapper scheduleMapper;
    @Override
    public List<Schedule> selectAllIncludingDeleted() {
        return scheduleMapper.selectAllIncludingDeleted();
    }

    @Override
    public ResponseResult clazzPage(QueryCondition<Schedule> queryCondition) {
        Page<Schedule> schedulePage = new Page<>(queryCondition.getPage(), queryCondition.getLimit());
        Date classTime = queryCondition.getSearchParams().getClassTime();

        LambdaQueryWrapper<Schedule> lambda = new QueryWrapper<Schedule>().lambda();
        lambda.eq(ObjectUtils.isNotEmpty(classTime), Schedule::getClassTime, classTime)
                        .orderByDesc(Schedule::getClassTime);

        baseMapper.selectPage(schedulePage, lambda);

        long total = schedulePage.getTotal();
        List<Schedule> list = schedulePage.getRecords();


        return ResponseResult.success().data("total", total).data("tableData", list);
    }
}




